package controller;

import implementor.BalancePaymentDaoImplementor;
import implementor.CardDaoImplementor;
import implementor.ChequeDaoImplementor;
import implementor.TransactionDaoImplementor;
import implementor.TransationPaymentDaoImplementor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import utilities.AppUtilites;
import utilities.Constants;
import utilities.ViewUtilites;
import views.accounting.PopUpAccounting;

import daoInterface.BalancePaymentDao;
import daoInterface.CardDao;
import daoInterface.ChequeDao;
import daoInterface.TransactionDao;
import daoInterface.TransationPaymentDao;
import dto.BalancePayment;
import dto.Card;
import dto.Cheque;
import dto.Transactions;
import dto.TransationPayment;

public class PopUpAccountingController implements ActionListener{

	private PopUpAccounting view;
	private Cheque chmodel;
	private Card cardmodel;
	
	private DefaultTableModel dm;
	
    private Vector<Cheque> cheques;
	private Vector<Card> cards;
	
	private static int srNo=1;
	
	public PopUpAccountingController() {
	
	}



	public PopUpAccountingController(PopUpAccounting view) {
		super();
		this.view = view;
		view.actionlisteners(this);
		cards=new Vector<Card>();
	}

	public void reactToAdd()
	{
		dm=(DefaultTableModel) view.getTable().getModel();
		if(view.getRdbtnCheque().isSelected()==true)
		{
			dm.addRow(new Object[]{srNo++,"N.A",view.getTfchequeno(),view.getTfBank(),view.getTfBranch(),view.getTfChequeDate(),view.getTfAmountCheque()});
			fillInCheque();
		}
		if(view.getRdbtnCreditdebitCard().isSelected()==true)
		{
			dm.addRow(new Object[]{srNo++,view.getTfReferenceNo(),"N.A","N.A","N.A","N.A",view.getTfAmountCard()});
			fillInCard();
		}
		
	}

	public void fillInCheque()
	{
		chmodel=new Cheque();
		chmodel.setamt(Double.parseDouble(view.getTfAmountCheque().getText().trim()));
		chmodel.setbankName(view.getTfBank().getText().trim());
		chmodel.setbranchName(view.getTfBranch().getText().trim());
		chmodel.setdate(view.getTfChequeDate().getText().trim());
		chmodel.setpaymentMethodId(Constants.CHEQUE);
		chmodel.setstatus(Constants.ACTIVE);
		
		cheques.add(chmodel);
	}

	public void fillInCard()
	{
		cardmodel=new Card();
		cardmodel.setPaymentMethodId(Constants.CARD);
		cardmodel.setReferenceNo(view.getTfReferenceNo().getText().trim());
		cardmodel.setCustomerName(view.getTfCustomerName().getText().trim());
	    cards.add(cardmodel);
	
	}

	public Vector<Cheque> getCheques() {
		return cheques;
	}
	
	public void setCheques(Vector<Cheque> cheques) {
		this.cheques = cheques;
	}
	
	public Vector<Card> getCards() {
		return cards;
	}
	
	public void setCards(Vector<Card> cards) {
		this.cards = cards;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String k=e.getActionCommand();
		if(k.equals("Add"))
		{
			reactToAdd();
		}
		if(k.equals("Cl"))
		{
			ViewUtilites.makeDateComponent(view.getTfChequeDate());
		}
		
	}
}
